<html>
<head><meta charset="utf-8"><title>array_chunks of size 0 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html">array_chunks of size 0</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204001667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204001667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204001667">(Jul 15 2020 at 19:30)</a>:</h4>
<p>leonardo-m made an interesting point on <a href="https://github.com/rust-lang/rust/issues/74373">#74373</a> (add <code>slice::array_chunks</code> to std).</p>
<blockquote>
<p>Could you please add a note here that says that future versions of this are allowed to panic at compile-time if N is 0 instead of run-time?</p>
</blockquote>



<a name="204002003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002003">(Jul 15 2020 at 19:33)</a>:</h4>
<p>While I fully agree that this is desirable, I can't really see how this is feasible</p>



<a name="204002197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002197">(Jul 15 2020 at 19:34)</a>:</h4>
<p>We could add a comment saying</p>
<blockquote>
<p>Note: This method currently panics at runtime if <code>N == 0</code>. This may get changed to error at compile time in the future <strong>without</strong> constituting a breaking change</p>
</blockquote>



<a name="204002411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002411">(Jul 15 2020 at 19:36)</a>:</h4>
<p>But how can we actually implement this in the future without breaking code like this</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">do_stuff</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">(</span><span class="n">arr</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">u8</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">arr</span><span class="p">.</span><span class="n">array_chunks</span>::<span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="p">().</span><span class="n">whatever</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="204002468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002468">(Jul 15 2020 at 19:37)</a>:</h4>
<p>We can't really just add a <code>where {N &gt; 0}</code> bound to this function in this case</p>



<a name="204002641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002641">(Jul 15 2020 at 19:38)</a>:</h4>
<p>We might add a compile warning if this method is ever used with <code>N == 0</code>, but I don't think we will ever be able to change this to an error after stabilizing it.</p>



<a name="204002680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204002680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204002680">(Jul 15 2020 at 19:39)</a>:</h4>
<p>It could presumably be a deny-by-default lint</p>



<a name="204003078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003078">(Jul 15 2020 at 19:42)</a>:</h4>
<p>will that work with coherence?</p>



<a name="204003101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003101">(Jul 15 2020 at 19:42)</a>:</h4>
<p>you can't turn off overlapping traits</p>



<a name="204003154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003154">(Jul 15 2020 at 19:43)</a>:</h4>
<p>what trait?</p>



<a name="204003393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003393">(Jul 15 2020 at 19:45)</a>:</h4>
<p><code>where N &gt; 0</code></p>



<a name="204003451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003451">(Jul 15 2020 at 19:46)</a>:</h4>
<p>not sure if I'm making sense, sorry</p>



<a name="204003489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003489">(Jul 15 2020 at 19:46)</a>:</h4>
<p><code>where {N &gt; 0}</code> isn't a trait but a generic bound.</p>



<a name="204003532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003532">(Jul 15 2020 at 19:46)</a>:</h4>
<p>We don't actually have a syntax for this rn, but think of it similar to <code>where T: Default</code></p>



<a name="204003571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003571">(Jul 15 2020 at 19:47)</a>:</h4>
<p>See <a href="https://github.com/rust-lang/rust/issues/68436">https://github.com/rust-lang/rust/issues/68436</a> for some more discussion about this</p>



<a name="204003586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003586">(Jul 15 2020 at 19:47)</a>:</h4>
<p>oh I see, it's entirely different machinery than <code>LengthAtMost32</code></p>



<a name="204003594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003594">(Jul 15 2020 at 19:47)</a>:</h4>
<p>ignore me then</p>



<a name="204003830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003830">(Jul 15 2020 at 19:49)</a>:</h4>
<p>It's similar, we could theoretically use negative <code>impl</code>s here, so:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/// implemented for all `[(); N]` with `N != 0`</span>
<span class="n">auto</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">NonZero</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="o">!</span><span class="n">NonZero</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">[();</span><span class="w"> </span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="204003938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204003938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204003938">(Jul 15 2020 at 19:50)</a>:</h4>
<p>and <code>fn array_chunks&lt;const N: usize&gt;() -&gt; Ty where [(); N]: NonZero {}</code></p>



<a name="204004168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204004168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204004168">(Jul 15 2020 at 19:52)</a>:</h4>
<p>So we theoretically could already add this bound rn and rewrite this bound in the future once we have a better story about const wf</p>



<a name="204005679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204005679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204005679">(Jul 15 2020 at 20:03)</a>:</h4>
<p>hm, cc <span class="user-mention" data-user-id="256759">@boats</span>, <span class="user-mention" data-user-id="119009">@eddyb</span>, <span class="user-mention" data-user-id="121053">@varkor</span>  it's probably desirable to already add this bound to <code>array_chunks</code>.</p>



<a name="204006421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204006421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204006421">(Jul 15 2020 at 20:09)</a>:</h4>
<p>idk <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> I think if we ever get a good concept for const wf bounds having these bounds here is expected and in general a <em>good idea</em></p>



<a name="204006761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204006761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204006761">(Jul 15 2020 at 20:12)</a>:</h4>
<p>But it will probably prevent calling these methods with generic parameters when the MVP lands on stable. This is hopefully rare though</p>



<a name="204008282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204008282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204008282">(Jul 15 2020 at 20:25)</a>:</h4>
<p>array_chunks will be unstable anyway so we can punt whether or not we should do that to some time before stabilizing the method</p>



<a name="204012146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204012146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204012146">(Jul 15 2020 at 20:59)</a>:</h4>
<p>Well, added a bound for now. Considering that relaxing the bound shouldn't break stuff while adding one can, this seems like it would cause less harm.</p>



<a name="204014083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204014083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204014083">(Jul 15 2020 at 21:15)</a>:</h4>
<p>Make sure to add that point to the tracking issue :-)</p>



<a name="204018780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204018780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204018780">(Jul 15 2020 at 22:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/array_chunks.20of.20size.200/near/204012146">said</a>:</p>
<blockquote>
<p>Well, added a bound for now. Considering that relaxing the bound shouldn't break stuff while adding one can, this seems like it would cause less harm.</p>
</blockquote>
<p>Well, removed that bound for now <a href="https://github.com/rust-lang/rust/issues/74383">#74383</a></p>



<a name="204026999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204026999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204026999">(Jul 15 2020 at 23:40)</a>:</h4>
<p>lol</p>



<a name="204052978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204052978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204052978">(Jul 16 2020 at 07:24)</a>:</h4>
<p>If we don't want to bubble up bounds we can also use user-defined post-monomorphization errors: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=5d44d3ae6d71021771242b935aac6513">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=5d44d3ae6d71021771242b935aac6513</a></p>



<a name="204053206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053206">(Jul 16 2020 at 07:28)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> bold plan to try and get me to give up static typing forever</p>



<a name="204053246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053246">(Jul 16 2020 at 07:28)</a>:</h4>
<p>(or alternatively, retreat into formal proof assistant territory)</p>



<a name="204053294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053294">(Jul 16 2020 at 07:29)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> but note that with bubbling, you'd get the error at the point where you're <em>choosing</em> an <code>N == 0</code>, not somewhere else deep down someone else's code or w/e</p>



<a name="204053312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053312">(Jul 16 2020 at 07:29)</a>:</h4>
<p>I think it's a good alternative for where we can't do breaking changes or where users "just give up" due to complex bounds</p>



<a name="204053365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053365">(Jul 16 2020 at 07:30)</a>:</h4>
<p>the plan was never to use bounds though?</p>



<a name="204053370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053370">(Jul 16 2020 at 07:30)</a>:</h4>
<p>at least no practical plan</p>



<a name="204053372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053372">(Jul 16 2020 at 07:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/array_chunks.20of.20size.200/near/204053294">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="124288">oli</span> but note that with bubbling, you'd get the error at the point where you're <em>choosing</em> an <code>N == 0</code>, not somewhere else deep down someone else's code or w/e</p>
</blockquote>
<p>I am working on this, so you at least get a note mentioning one site that caused it</p>



<a name="204053419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053419">(Jul 16 2020 at 07:31)</a>:</h4>
<p>my plan was always "repeat the expression somewhere in your public interface so that it's checked at the use site"</p>



<a name="204053427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053427">(Jul 16 2020 at 07:31)</a>:</h4>
<p>not <code>where N != 0</code></p>



<a name="204053443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053443">(Jul 16 2020 at 07:31)</a>:</h4>
<p>you don't have to tell me not to add a SAT solver dependency :P</p>



<a name="204053459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053459">(Jul 16 2020 at 07:31)</a>:</h4>
<p>which... is the manual version of exposed bodies I guess? <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="204053465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053465">(Jul 16 2020 at 07:31)</a>:</h4>
<p>but only exposing the fallible things</p>



<a name="204053514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053514">(Jul 16 2020 at 07:32)</a>:</h4>
<p>I'll have you know that exposed bodies is more responsible than post-monomorphization errors :P</p>



<a name="204053555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053555">(Jul 16 2020 at 07:32)</a>:</h4>
<p>but yeah, the same way you'll have to write <code>?const</code> or w/e soon, I want the interface to express the typesystem requirements</p>



<a name="204053594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053594">(Jul 16 2020 at 07:33)</a>:</h4>
<p>and <code>do_stuff::&lt;0&gt;(b"foo");</code> should error in type-check because <code>&lt;[u8; 0]&gt; as NotZero&gt;::MEM</code> doesn't evaluate successfully</p>



<a name="204053600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053600">(Jul 16 2020 at 07:33)</a>:</h4>
<p>you <em>still get</em> the custom errors!</p>



<a name="204053604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053604">(Jul 16 2020 at 07:33)</a>:</h4>
<p>in case that wasn't clear</p>



<a name="204053656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053656">(Jul 16 2020 at 07:34)</a>:</h4>
<p>you just get them in type-checking, and at the point where the problem is introduced</p>



<a name="204053666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053666">(Jul 16 2020 at 07:34)</a>:</h4>
<p>uh... this trait trick works on stable (modulo the custom message and the const generic)</p>



<a name="204053670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053670">(Jul 16 2020 at 07:34)</a>:</h4>
<p>not like in C++ where there can be a hundred template expansion levels in between</p>



<a name="204053692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053692">(Jul 16 2020 at 07:34)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> yes and  that's fine, the problem is when that associated constant is used <em>in a type</em></p>



<a name="204053699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053699">(Jul 16 2020 at 07:34)</a>:</h4>
<p>right</p>



<a name="204053710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053710">(Jul 16 2020 at 07:35)</a>:</h4>
<p>I keep forgetting, thx</p>



<a name="204053725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053725">(Jul 16 2020 at 07:35)</a>:</h4>
<p>I keep repeating myself, you just have to show me this and I'll keep restating it lmao</p>



<a name="204053739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053739">(Jul 16 2020 at 07:35)</a>:</h4>
<p>like I just left a comment a few hours ago on one of the issues</p>



<a name="204053741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053741">(Jul 16 2020 at 07:35)</a>:</h4>
<p><span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="204053751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053751">(Jul 16 2020 at 07:35)</a>:</h4>
<p>I haven't caught up on github notifications today</p>



<a name="204053799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053799">(Jul 16 2020 at 07:36)</a>:</h4>
<p>your example can be a warning + runtime panic</p>



<a name="204053807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053807">(Jul 16 2020 at 07:36)</a>:</h4>
<p>the bad constant is just used at runtime</p>



<a name="204053819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053819">(Jul 16 2020 at 07:36)</a>:</h4>
<p>the problem is when you stop being able to reason about types</p>



<a name="204053860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053860">(Jul 16 2020 at 07:36)</a>:</h4>
<p>we've introduced WF rules for similar things around associated types</p>



<a name="204053878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053878">(Jul 16 2020 at 07:37)</a>:</h4>
<p>where <em>we really want</em> them to hold</p>



<a name="204053887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053887">(Jul 16 2020 at 07:37)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> and I haven't even considered any lifetime implications lol</p>



<a name="204053896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053896">(Jul 16 2020 at 07:37)</a>:</h4>
<p>since you can't check lifetime constraints at codegen time. WOW</p>



<a name="204053936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053936">(Jul 16 2020 at 07:38)</a>:</h4>
<p><del>@<strong>oli</strong> thanks, I think I can demolish the argument for post-monomorphization const-eval errors <em>forever</em></del></p>



<a name="204053975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053975">(Jul 16 2020 at 07:38)</a>:</h4>
<p><del>although it might mean that some stuff we do today is arguably unsound</del></p>



<a name="204053983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204053983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204053983">(Jul 16 2020 at 07:38)</a>:</h4>
<p>why did I forget lifetimes exist lmao</p>



<a name="204054110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204054110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204054110">(Jul 16 2020 at 07:40)</a>:</h4>
<p>hmm but how can I abuse this, most of the stuff seems to be handled by where clauses already :(</p>



<a name="204054289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/array_chunks%20of%20size%200/near/204054289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/array_chunks.20of.20size.200.html#204054289">(Jul 16 2020 at 07:43)</a>:</h4>
<p>I might still try to look into it, it's suspicious but I may have overreacted</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>